#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# @Project : RAG-demo
# @File    : test.py
# @IDE     : PyCharm
# @Author  :ZH
# @Time    : 2025/6/30 15:18
from io import BytesIO

from elasticsearch import Elasticsearch

from util import ZhipuFileUtil

# 封装一个调用异步方法的操作
import asyncio

from util.elasticsearch_util import ElasticsearchBM25Client


def arun():
    # 测试文件解析
    # file_path = './文本模式文件解析测试.txt'
    # api_key = '06e1eae173bf9fe678ca21dd32cf0fa3.oJn4E7me2OOB084p'
    # base_url = 'https://open.bigmodel.cn/api/paas/v4/files'
    # zhipu_util = ZhipuFileUtil(api_key=api_key, base_url=base_url)
    # with open(file_path, 'rb') as file_object:
    #     # 读取文件内容
    #     content = file_object.read()
    #     # 创建 BytesIO 对象
    #     file_object = BytesIO(content)
    #     # 调用提取文件内容方法
    #
    #     asyncio.run(zhipu_util.extract_file_content(file_object=('文本模式文件解析测试.txt', file_object)))

    # 测试文本转向量
    # from util.embedding_rerank_util import bce_embedding_server
    # content = "这是一个测试文本，用于生成向量表示。"
    # result = asyncio.run(bce_embedding_server(content))
    # print(result)

    # 测试精排
    # from util.embedding_rerank_util import bce_rerank_server
    # query = "张飞是谁"
    # documents = [
    #     "张飞是三国时期蜀汉的重要将领，以勇猛著称。",
    #     "这是第二条文档",
    #     "这是第三条文档"
    # ]
    # result = asyncio.run(bce_rerank_server(query, documents))
    # print(result)

    # 测试ES
    l = ElasticsearchBM25Client(host='elasticsearch.vip.cpolar.cn', port=80)
    l.create_index()
    print('1111')
    pass


if __name__ == '__main__':
    # 测试一下
    arun()
